﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using cndp.Model.IModel;

namespace cndp.Model
{
    /// <summary>
    /// DiverWithJumpCodes - DiverWithJumpCodesklassen innehåller en simhoppare och vilka simhoppskombinationer som simhopparen har/ska hoppa.
    /// </summary>
    [Serializable]
    public class DiverWithJumpCodes
    {
        [XmlElement("Diver")]
        public Diver Diver { get; set; }
        [XmlElement(typeof(JumpCodesAndStyle))]
        public BindingList<JumpCodesAndStyle> JumpCodesandStyle;

        public DiverWithJumpCodes(string name, string gender, string personalCodeNumber, string nationality, string club)
        {
            Diver = new Diver(name, gender, personalCodeNumber, nationality, club);
            JumpCodesandStyle = new BindingList<JumpCodesAndStyle>();
        }

        public DiverWithJumpCodes() 
        {
            Diver = new Diver();
            JumpCodesandStyle = new BindingList<JumpCodesAndStyle>();
        }

        public void AddJumpcodeAndStyle(int jumpId, string style)
        {
            JumpCodesandStyle.Add(new JumpCodesAndStyle(jumpId, style));
        }
        public void RemoveJumpcodeAndStyle(int index)
        {
            JumpCodesandStyle.RemoveAt(index);
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            var objAsDiverWithJumpCodes = obj as DiverWithJumpCodes;
            if (objAsDiverWithJumpCodes == null) return false;
            return Equals(objAsDiverWithJumpCodes);
        }


        public bool Equals(DiverWithJumpCodes other)
        {
            if (other == null) return false;
            return (Diver.PersonalCodeNumber.Equals(other.Diver.PersonalCodeNumber));
        }
    }
}
